package study.domain.user;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EntityListeners;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.Size;

import lombok.Data;
import lombok.ToString;

import org.hibernate.annotations.Table;

import com.barney.support.domain.HasCreatedAndUpdatedDate;
import com.barney.support.jpa.CreatedAndUpdatedDateListener;

/**
 * 사용자
 *
 * @author Barney Kim
 */
@Entity(name = "users")
@Table(appliesTo = "users", comment = "사용자", indexes = {
		@org.hibernate.annotations.Index(name = "udx_users", columnNames = { "username" }) })
@EntityListeners(CreatedAndUpdatedDateListener.class)
@Data
@ToString(exclude = { "password" })
public class User implements Serializable, HasCreatedAndUpdatedDate {

	private static final long serialVersionUID = -1123086922264820387L;

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Column
	private Long userId;

	@Size(min = 2, max = 20)
	@Column(unique = true, nullable = false, length = 20)
	private String username;

	@Size(min = 6, max = 20)
	@Column(nullable = false, length = 32)
	private String password;

	@Size(min = 2, max = 20)
	@Column(nullable = false, length = 20)
	private String name;

	@Column(nullable = false)
	private boolean enabled;

	@Temporal(TemporalType.TIMESTAMP)
	@Column(nullable = false, updatable = false)
	private Date createdDate;

	@Temporal(TemporalType.TIMESTAMP)
	@Column(nullable = false)
	private Date updatedDate;

	public User() {
		//
	}

	public User(Long userId) {
		this(userId, null, null, null);
	}

	public User(Long userId, String username, String name, String password) {
		this.userId = userId;
		this.username = username;
		this.name = name;
		this.password = password;
	}
}
